package code.lucamarrocco.deployr;

import java.security.*;

public class Md5 {

	private static final String hex(byte[] array) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < array.length; ++i) {
			sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).toLowerCase().substring(1, 3));
		}
		return sb.toString();
	}

	public static final String md5(String string) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			return hex(md.digest(string.getBytes("utf8")));
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

}
